﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb">
            <li><a href="/Home/Home">Home</a></li>
            <li><a href="/Core/Introduction"> Sanelib Core</a></li>
            <li class="active">Command Processor</li>
        </ol>
            
            <div id="introduction">
                <h1 class="text-left">Command Processors</h1>
                <p>Command Processors is do process of the command and handle the command. In the Command processor implement by Icommandprocessor and in that pass the command. Icommand processor is genric interface and that contain dynamic process. Process method pass one argument as command. Icommand Processor extends by Icommand and that contain two methods.</p>
                <pre><code>public interface ICommand
    {
    	Guid GetAggregateId();
        ErrorResult Validate();
	}</code></pre>
                <pre><code>public interface ICommandProcessor&lt;in tcommand&gt; where TCommand : ICommand
    {
        dynamic Process(TCommand command);
    }</code></pre>
                <p><br />Command Processor contain main two methods.</p>
                <ol style="padding-left: 30px;">
                    <li>
                        Processor Contructor-<p>Processor contructor's intilise the variables. like repository variable.</p>
                        <pre><code>public EditMemberProcessor(IRepository&lt;member&gt; memberRepository)
        {
            _memberRepository = memberRepository;
        }</code></pre>
                    </li>
                    <li>
                        Process Method-<p>Process method must be dynamic becuase Icommandprocesser contain method process method that dynamic and pass one command as argument. Process method is handle command and according response to us.</p>
                        <pre><code>public dynamic Process(EditMember command)
        {.......}
                        </code></pre>
                        <p>Command processer's return value as string to user id. Command processor return value as response to client.</p>
                        <pre><code>var response = new WebApiResultResponse();<br />.<br />.<br />.<br />return response.Message = member.Id.ToString();</code></pre>
                    </li>
                </ol>
                <p>WebApiResultResponse() contain two variables IsSuccess and Message. In CommandProcessor return value in turn of web api response. WebApiResponse return into string message or boolean value of IsSuccess. IsSuccess for when opretion done successfully then pass true.</p>
                <pre><code>public class WebApiResultResponse : WebApiResonseBase
    {
        public bool IsSuccess { get; set; }
        public string Message { get; set; }
    }</code></pre>
                <p>WebApiResponseBase is for the create uri string and redirect bool that return value of opertion. WebApiResponseBase have create method that rerturn value Uri and RedirectRequired values.</p>
                <pre><code>public interface IWebApiResponse
    {
        string Uri { get; set; }
        bool RedirectRequired { get; set; }
    }</code></pre>
                <p>WebApiResponseBase implemented by IWebApiResponse. IWebApiResponse have two methods Uri and RedirectRequired.</p>
            </div>
   